class out
{
    public int a=0;
    public void add1()
    {
        a++;
    }
    public void add3()
    {
        synchronized (this)
        {
            a++;
        }
    }
    public synchronized void add2()
    {
        synchronized (this)
        {
            a++;
        }
    }
}



public class text99 {
    public static void main(String[] args) {
        out b=new out();
        Thread thread1=new Thread(new Runnable() {
            @Override
            public void run() {
                int i=0;
                for(i=0;i<500000;i++)
                {
                   // b.add2();
                    b.add1();
                }


            }
        });
        Thread thread2=new Thread(new Runnable() {
            @Override
            public void run() {
                int j=0;
                for(j=0;j<500000;j++)
                {
                    //b.add2();
                    b.add3();
                }
            }
        });
        thread1.start();
        thread2.start();
        try {
            thread1.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        try {
            thread2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(b.a);

    }
}
